<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title> 店铺发货</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/Public/admin/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/font-awesome/font-awesome.min.css">
    <!-- Ionicons -->
    <!--link rel="stylesheet" href="/Public/admin/adminlte/plugins/ionicons/ionicons.min.css"-->
    <!-- Theme style -->
    <link rel="stylesheet" href="/Public/admin/adminlte/dist/css/adminLTE.min.css">
    <!-- adminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="/Public/admin/adminlte/dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/daterangepicker/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="/Public/admin/adminlte/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <!-- common css -->
    <link rel="stylesheet" href="/Public/admin/css/common.css">
    <!-- jQuery 2.2.3 -->
    <script src="/Public/admin/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <!-- jQuery UI 1.11.4 -->
    <script src="/Public/admin/adminlte/bootstrap/js/jquery-ui.min.js"></script>
    <script src="/Public/admin/js/jquery.validate.min.js"></script>
    <script src="/Public/admin/js/jquery.validate.config.js"></script>
    <script src="/Public/admin/js/common.js?v=20170213001"></script>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="/Public/admin/adminlte/plugins/html5shiv/html5shiv.min.js"></script>
    <script src="/Public/admin/adminlte/plugins/html5shiv/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-mini">



    <!-- 内容 -->
    <section class="content" >


        <div class="box box-default">
            <div class="box-header with-border">
                <h3 class="box-title">发货:{$delivery['detail']['order_id']}
                    【{$delivery['identity']['status']}】
                   </h3>
            </div>
            <!-- /.box-header -->

      <form method="post" action="{:U('orders/doDelivery')}"   id="order-delivery-form">
            <div class="box-body">


                <table cellpadding="0" cellspacing="0" class="table table-bordered" id="tb1">
                    <tbody><tr>
                        <th>订单号:</th>
                        <td>{$delivery.detail.order_id}
                            【 <if condition="$delivery['detail']['ship_status'] eq 0 ">未发货
                                <elseif condition="$delivery['detail']['ship_status'] eq 1" />已发货
                                <!--<elseif condition="$delivery['detail']['ship_status'] eq 2" />部分发货
                                <elseif condition="$delivery['detail']['ship_status'] eq 3" />部分退货
                                <elseif condition="$delivery['detail']['ship_status'] eq 4" />已退货-->
                            </if> 】
                        </td>
                        <th>下单日期:</th>
                        <td>{$delivery.detail.createtime}</td>
                    </tr>
                    <tr>
                        <th>配送方式:</th>
                        <td>
                            <select type="select" name="delivery" id="delivery" class=" x-select">
                               <volist name="delivery['dlytype']" id="item">
                                   <option value="{$item.dt_id}" <if condition="$item['dt_id'] eq $delivery['Select_dt']['dt_id']">selected="selected" </if>>
                                   {$item.dt_name}
                                   </option>
                                 </volist>
                            </select></td>
                        <th>配送费用:</th>
                        <td>￥{$delivery.detail.cost_freight|number_format=###, 2, '.', ''} </td>
                    </tr>
                    <tr class="shop-delivery <if condition="$delivery['Select_dt']['dt_id'] neq 1">hide</if>" >
                        <th>配送人姓名:</th>
                        <td><div><div><input type="text" name="delivName" value=""></div></div></td>
                        <th>配送人电话:</th>
                        <td><div><div><input type="text" name="delivMobile" value=""></div></div> </td>
                    </tr>



                    <tr <if condition="$delivery['Select_dt']['dt_id'] eq 3"> class='hide' </if> id='isKd'>
                        <th>物流公司:</th>
                        <td>
                            <select   type="select" name="logi_id" id="logi_id" class=" x-select">
                                <option value="0">选择物流公司</option>
                                <volist name="delivery['dlycorp']" id="item">
        <option value="{$item['corp_id']}"  <if condition="$delivery['se_corp_id'] eq $item['corp_id']">selected="selected" </if>>{$item['name']}</option>
                                </volist>
                            </select>

                        </td>
                        <th>物流单号:</th>
                        <td><div><div><input class="x-input" type="text" id="logi_no" name="logi_no" width="100" ></div></div></td>
                    </tr>
                    <if condition="$delivery['detail']['is_zt'] neq 1">
                        <input type="hidden" name="is_aa" value="no_zt" />
                     <else/>
                        <input type="hidden" name="is_aa" value="zt" />
                    </if>
                    <tr>
                        <if condition="$delivery['detail']['is_zt'] neq 1">

                            <th>物流费用:</th>
                         <td><input class="x-input" type="text" id="money"  name="money" value="{$delivery.detail.cost_freight|number_format=###, 2, '.', ''}" width="50"></td>
                            <th>邮政编码:</th>
                            <td><div><div><input class="x-input" type="text" name="ship_zip" id="ship_zip" value="{$delivery.detail.ship_zip}" width="80"></div></div></td>
                        <else/>
                            <input class="x-input" type="hidden" id="money"  name="money" value="{$delivery.detail.cost_freight|number_format=###, 2, '.', ''}" width="50">
                         </if>





                        <!--<th>物流保价:</th>
                        <td>
                            <input name="is_protect" type="radio" id="dom_el_e543c83-1" value="false" checked="checked"><label for="dom_el_e543c83-1">否</label><br><input name="is_protect" type="radio" id="dom_el_e543c83-2" value="true"><label for="dom_el_e543c83-2">是</label></td>
                    </tr>
                    <tr>
                        <th>保价费用:</th>
                        <td colspan="3"><input class="x-input" type="text" name="cost_freight" value="0.000" width="50" id="dom_el_e543c84"></td>
                    </tr>-->
                    <tr>
                        <th>收货人姓名:</th>
                        <td><div><div><input class="x-input" type="text" name="ship_name" id="ship_name" value="{$delivery.detail.ship_name}" width="80"></div></div></td>
                        <th>手机:</th>
                        <td><div><div><input class="x-input" type="text" name="ship_mobile" id="ship_mobile" value="{$delivery.detail.ship_mobile}" width="150">
                        </div></div></td>

                    </tr>

                    <tr>
                        <th>地区:</th>
                        <td colspan="3">
                            {$delivery.detail.ship_area}
                            <input type="hidden" value="{$delivery.detail.ship_area}" id="ship_area" name="ship_area"/>
                        </td>
                    </tr>
                    <tr>
                        <th>地址:
                        <td colspan="3"><input class="x-input" type="text" name="ship_addr" id="ship_addr" value="{$delivery.detail.ship_addr}" style="width:360px" ></td>
                    </tr>
                    <tr>
                        <th>发货单备注:</th>
  <td colspan="3"><textarea type="textarea" name="memo" id="memo" style="width:95%" >{$delivery.detail.memo}</textarea></td>
                    </tr>
                    </tbody></table>


                <!-- /.row -->
            </div>
            <input type="hidden" value="{$delivery.detail.order_id}" id="order_id" name="order_id"/>
            <!-- /.box-body -->
            <div class="box-footer">
                <div class="division">
                    <table class="table table-hover" style="margin-left: 10px; width: 99%;">
                        <tbody>
                        <tr>
                            <th>货号</th>
                            <th>货品名称</th>
                            <th>当前库存</th>
                            <th>冻结</th>
                            <th>购买数量</th>
                            <th>已发货量</th>
                            <th>此单发货</th>
                        </tr>

                        <volist name="delivery.product" id="item">
                            <tr>
                                <td>{$item.bn}</td>
                                <td>{$item.name}
                                    <if condition="$item.backsend neq ''">
                                   <span style="color: #ff0000">{$item.backsend}</span>

                                    </if>
                                </td>
                                <td>{$item.store}</td>
                                <td>{$item.freez}</td>
                                <td>{$item.nums}</td>
                                <td>{$item.sendnum}</td>
                                <td>


                                        <if condition="$item.needsend neq 0">
                                            <input class="x-input" type="text" id="send" name="send[{$item.item_id}]" value="{$item.needsend}" width="50"  readonly="readonly" style="border: none"  >
                                            <else/>
                                            无需发货
                                        </if>



                                </td>
                            </tr>
                        </volist>

                        <tr>

                            <td colspan="7"><div style="width: 100px; margin:0 auto; margin-top: 20px; ">
                                <button type="submit" class="btn btn-block btn-primary btn-lg"  >发货</button></div></td>

                        </tr>

                        </tbody></table>
                </div>
            </div>

      </form>

       </div>




    </section>

<!-- 底部 -->
<!-- jQuery 2.2.3 -->
<!-- Bootstrap 3.3.6 -->
<script src="/Public/admin/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- adminLTE App -->
<script src="/Public/admin/adminlte/dist/js/app.min.js"></script>
<!-- adminLTE for demo purposes -->
<script src="/Public/admin/adminlte/dist/js/demo.js"></script>
<script src="/Public/admin/adminlte/plugins/iCheck/icheck.min.js"></script>


<!--<script src="/Public/js/distpicker.data.js"></script>
<script src="/Public/js/distpicker.js"></script>-->
</body>
</html>



<script type="text/javascript">
    $(function() {

            window._isSaved = false;

       /* $(".distpicker1").distpicker();*/
        $("#province").val('选择省');
        $("#city").val('选择市');
        $("#area").val('选择区');

        $("#order-delivery-form").validate({
            rules: {
                money:{
                    isPrice: true
                },
                ship_mobile:{
                    isMobile: true
                },
                /*delivName:{
                    required: true,
                    maxlength: 40,
                },*/
                /*delivMobile:{
                    required: true,
                    isMobile: true,
                },*/
                logi_no:{
                    maxlength: 40,
                    number:true
                },
                ship_name: {
                    required: true,
                    maxlength: 40,
                },
                ship_zip:{
                        isZipCode: true
                }
            },
            messages:{
                ship_name:{
                    required: "请输入收货人姓名",
                    maxlength: "收货人姓名不能超过40个字符"
                },
              /*  delivMobile:{
                    required: "请输入配送人电话",
                },
                delivName:{
                    required: "请输入配送人姓名",
                    maxlength: "配送人姓名不能超过40个字符"
                },*/

            },
            submitHandler: function(form){
                //form.submit();   //提交表单
               console.log(window._isSaved);
               if(window._isSaved){
                    return;
                }

                toDelivery();

            }
        });


    })

    function toDelivery() {
       var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

        $.ajax({
            url:$('form').attr('action'),
            type:'post',
            data:$('#order-delivery-form').serialize(),
            dataType:'json',
            success:function (data) {
                if(data.status ==0){
                    alert(data.msg);
                    return false;
                }else{
                   alert(data.msg);
                    window._isSaved = true;
                    $('.btn-lg').attr({"disabled":"disabled"});
                     parent.layer.close(index);
                     parent.location.reload();
                }


            },
            error:function (err) {
                alert('参数错误');
                window._isSaved = false;
            }

        })

    }
    $('#delivery').on('change',function () {
        $_this =$(this);
        if($_this.val() == 1){
            $('.shop-delivery').removeClass('hide');
        }
        if($_this.val() != 1 ){
            //快递
            $('.shop-delivery').removeClass('hide');

        }

        if($_this.val() == 2 ){
            //快递
            $('.shop-delivery').addClass('hide');

        }

        if($_this.val() != 3 ){

            $('#isKd').removeClass('hide');
        }
        if($_this.val() == 3 ){
            //快递
            $('.shop-delivery').addClass('hide');
            $('#isKd').addClass('hide');
        }


    })



</script>
